package com.zc.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class MainService extends Service{
	
	public static final String TAG = MainService.class.getSimpleName();
	public static final String ACTIONONE = "com.zcl.start";
	public static final String ACTIONTWO = "com.zcl.end";
	
	@Override
	public void onCreate() {
		Log.i(TAG, "onCreate");
		super.onCreate();
	}

	@Override
	public void onStart(Intent intent, int startId) {
		Log.i(TAG, "onStart");
		if (intent.getAction().equals("com.zcl.start")) {
			Log.i(TAG, "start event");
			new Thread(){
				@Override
				public void run() {
					// TODO Auto-generated method stub
					Intent i = new Intent("com.zcl.end");
					MainService.this.startService(i);
					super.run();
				}
				
			}.start();
			
			
		} else if (intent.getAction().equals(ACTIONTWO)) {
			Log.i(TAG, "end event");
			
			new Thread(){

				@Override
				public void run() {
					Log.i(TAG, ".......");
					
					MainService.this.stopSelf();
					super.run();
				}
			}.start();
			
		}
		super.onStart(intent, startId);
	}

	@Override
	public void onDestroy() {
		Log.i(TAG, "onDestroy");
		super.onDestroy();
	}

	@Override
	public IBinder onBind(Intent intent) {
		Log.i(TAG, "onBind");
		return null;
	}
}
